home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
5 Star Games: DOS Edition 2
/
5 Star Games - DOS Edition (1995)(Ready to Run).iso
/
dbc
/
db_pswd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
7KB
|
228 lines
/****************************************************************************/
/* DATABOSS MODULE: DB_PSWD.C */
/****************************************************************************/
#include "db_lsc.h"
#ifndef __TURBOC__
#include <graph.h>
#include <sys\types.h>
#define _close(h) close(h)
#endif
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys\stat.h>
#include "db_types.h"
#include "db_curs.h"
#include "db_file.h"
#include "db_funcs.h"
#include "db_gvar.h"
#include "db_key.h"
#include "db_str.h"
#include "db_win.h"
#include "db_util.h"
#include "db_pswd.h"
/***************************** INTERNAL TYPES *****************************/
typedef struct {
uchar exeid[9];
uchar password[9];
} default_rec;
/*************************** INTERNAL CONSTANTS ***************************/
static uchar TwistMask[9] = "ôö╘f8d¢º";
static default_rec def = {"öDBPSWD_","\xB9\x15\xE1\xB3\xC7\xED\xA9\x8C"};
/*************************** INTERNAL VARIABLES ***************************/
static byte longest;
static int pwdfile;
static bool pwdopen;
static uchar opname[9],pword[9];
static bool initialized = False;
/***************************** IMPLEMENTATION *****************************/
strptr twist(string sout, byte mode, string instr, byte s) /* SN 3.5 */
{
int b,c,ilen;
string ts;
ilen = strlen(instr);
for (b = 0 ; b < ilen ; b++) {
c = (ilen - (b+1) + 3) % ilen;
if (mode > 0)
ts[b] = instr[c] + TwistMask[(c+1) % 8] + (9 - s); /* SN 3.5 */
else
ts[b] = instr[c] - TwistMask[(b+1) % 8] + (9 - s); /* SN 3.5 */
}
ts[ilen] = '\0';
return (strcpy(sout,ts));
}
void convertrec(passwd_rec *pwrec)
{
if (pwrec->operator[0] < ' ') { /* Pascal data record if length byte detected */
memmove(&pwrec->operator[0],&pwrec->operator[1],8);
pwrec->operator[8] = '\0';
memmove(&pwrec->password[0],&pwrec->password[1],8);
pwrec->password[8] = '\0';
memmove(&pwrec->sec_code[0],&pwrec->sec_code[1],1);
pwrec->sec_code[1] = '\0';
}
}
bool pswdfound(void)
{
int i;
uchar ch, compstr[9];
passwd_rec passwd;
bool pswdmatch;
upper(pword,pword);
upper(compstr,twist(compstr,0,def.password,9)); /* SN 3.5 */
if ((strcmp(opname,"SYSOP ") == 0) && (strcmp(pword,compstr) == 0)) {
strcpy(gvar->operator,"SYSOP ");
gvar->sec = 9;
pswdmatch = True;
}
else {
pswdmatch = False;
if (pwdopen) {
if (filelength(pwdfile) > sizeof(passwd_rec)) {
i = 1;
ch = ' ';
do {
lseek(pwdfile,(long) (i*sizeof(passwd_rec)),SEEK_SET);
read(pwdfile,(void *)&passwd,sizeof(passwd_rec));
convertrec(&passwd);
upper(compstr,twist(compstr,0,passwd.password,(byte) ival(passwd.sec_code))); /* SN 3.5 */
i++;
if (kpressed()) ch = getkey();
pswdmatch = (bool) ((strcmp(pword,compstr) == 0) &&
(strcmp(opname,passwd.operator) == 0) &&
(passwd.recstat == 0));
} while ((ch != QitKey) && (!pswdmatch) &&
(i < (int)(filelength(pwdfile)/sizeof(passwd_rec))));
}
if (pswdmatch) {
gvar->sec = (byte) ival(passwd.sec_code);
strcpy(gvar->operator,passwd.operator);
}
}
}
return (pswdmatch);
}
void logon(void)
{
bool tb;
winptr twinp;
pathstr fname;
uchar tpic[3];
strcpy(tpic, "8X");
gvar->sec = 0;
if (openwin(0,18,10,longest,1,78,78,8,"─┐│┘─└│┌",TopCnt,LSC_LogonOrEsc)) { /* SN 3.5 */
twinp = curwin;
twinp->disp = True;
dispwindow(twinp);
strip(fname,strconcat(fname,thisprog.fdir,gvar->fname,".PWD",NULL));
pwdopen = (bool) ((pwdfile = open(fname,O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) != -1);
writewxy(LSC_OperatorPr,0,1,1,twinp); /* SN 3.5 */
strcpy(opname," ");
tpic[1] = Pic_U; /* operator name entry in upper case */
edt_fld(strlen(LSC_OperatorPr)+1,1,opname,_Ch,tpic,0,78,twinp); /* SN 3.5 */
writewxy(LSC_PasswordPr,0,1,1,twinp); /* SN 3.5 */
tpic[1] = Pic_B; /* no echo of following password */
do {
strcpy(pword," ");
edt_fld(strlen(LSC_PasswordPr)+1,1,pword,_Ch,tpic,0,78,twinp); /* SN 3.5 */
tb = pswdfound();
if (!tb) noise(900,0.1);
} while ((exitcode != QitKey) && !(tb && ((exitcode == XeptKey) || (exitcode == Enter))));
if (pwdopen) _close(pwdfile);
closewin(&twinp);
}
}
strptr updpword(string sout, string oldpw, byte s)
{
winptr twinp;
uchar pw1[9],pw2[9];
uchar tpic[3];
strcpy(tpic, "8X");
sout[0] = '\0';
if (openwin(0,18,10,longest,1,78,78,8,"─┐│┘─└│┌",TopCnt,LSC_ChangePasswordPr)) { /* SN 3.5 */
twinp = curwin;
twinp->disp = True;
dispwindow(twinp);
tpic[1] = Pic_B; /* no echo of password */
do {
strcpy(pw1," ");
strcpy(pw2,pw1);
writewxy(LSC_PasswordPr,0,1,1,twinp); /* SN 3.5 */
edt_fld(strlen(LSC_PasswordPr)+1,1,pw1,_Ch,tpic,0,78,twinp); /* SN 3.5 */
upper(pw1,pw1);
if (exitcode != QitKey) {
writewxy(LSC_VerifyPr,0,1,1,twinp); /* SN 3.5 */
edt_fld(strlen(LSC_PasswordPr)+1,1,pw2,_Ch,tpic,0,78,twinp); /* SN 3.5 */
upper(pw2,pw2);
if ((strcmp(pw1," ") == 0) || (strcmp(pw1,pw2) != 0)) noise(2000,0.1);
}
} while ((exitcode != QitKey) && !((strcmp(pw1," ") != 0) && (strcmp(pw1,pw2) == 0)));
twist(pw1,1,pw1,s); /* SN 3.5 */
if ((exitcode != QitKey) && (strcmp(pw1,oldpw) != 0)) strcpy(sout,pw1);
closewin(&twinp);
}
return(sout);
}
void updmaster(void)
{
winptr twinp;
uchar pw1[9],pw2[9];
updpword(pw1,def.password,9); /* SN 3.5 */
if (pw1[0] != '\0') {
strcpy(def.password,pw1);
message(NULL,LSC_UpdatingMaster); /* SN 3.5 */
updexe(def.exeid,sizeof(def));
message(NULL,"");
}
}
void setlongest(void)
{
longest = maximum(strlen(LSC_LogonOrEsc), strlen(LSC_PasswordPr)); /* SN 3.5 */
longest = maximum(longest, strlen(LSC_ChangePasswordPr)); /* SN 3.5 */
longest = maximum(longest, strlen(LSC_VerifyPr)); /* SN 3.5 */
longest = maximum(longest, strlen(LSC_UpdatingMaster)); /* SN 3.5 */
longest = maximum(longest, strlen(LSC_OperatorPr)); /* SN 3.5 */
longest += 12; /* SN 3.5 */
}
/********************** UNIT INITIALIZATION/EXIT CODE *********************/
void db_pswd_init(void)
{
if (!initialized) {
initialized = True;
db_funcs_init();
db_gvar_init();
db_key_init();
db_util_init();
db_win_init();
setlongest();
}
}
/***************************** END OF DB_PSWD.C ***************************/